using System;
using System.Collections.Generic;

namespace ADEVSO.Data.Sql
{
    public struct Column
    {
        public String TableName;
        public String ColumnName;
        public String DataType;
        public Int32 MaxLength;
        public Boolean AllowNulls;
        public Object Value;
        public Boolean IsPrimaryKey;
        public Boolean IsForeignKey;
        public Boolean IsIdentity;
    }

    public struct PrimaryKey
    {
        public String PrimaryKeyName;
        public String TableName;
        public String ColumnName;
    }

    public struct ForeignKey
    {
        public String ForeingKeyName;
        public String TableName;
        public String ColumnName;
        public String ReferencedTableName;
        public String ReferencedColumnName;
    }

    public struct Identity
    {
        public String TableName;
        public String ColumnName;
    }

    static public partial class Extensions
    {
        static public bool Contains(this List<Column> Columns, String TableName)
        {
            foreach (Column column in Columns)
                if (column.TableName.Equals(TableName))
                    return true;
            return false;
        }

        static public bool Contains(this List<PrimaryKey> PKs, String ColumnName)
        {
            foreach (PrimaryKey pk in PKs)
                if (pk.ColumnName.Equals(ColumnName))
                    return true;
            return false;
        }

        static public bool Contains(this List<ForeignKey> FKs, String ColumnName)
        {
            foreach (ForeignKey fk in FKs)
                if (fk.ColumnName.Equals(ColumnName))
                    return true;
            return false;
        }

        static public List<String> ToStringArray(this List<ForeignKey> FKs)
        {
            List<String> result = new List<String>();
            foreach (ForeignKey fk in FKs)
                result.Add(fk.ReferencedTableName);
            return result;
        }

        static public bool Contains(this List<Identity> Identities, String ColumnName)
        {
            foreach (Identity identity in Identities)
                if (identity.ColumnName.Equals(ColumnName))
                    return true;
            return false;
        }
    }
}
